Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ws = null;
- var wsEventController = null;
- $(function () {
- ws = new jXSockets.xWebSocket("ws://127.0.0.1:4502/GenericText", jXSockets.WEBSOCKET);
- wsEventController = new jXSockets.xWebSocket("ws://127.0.0.1:4502/EventController", jXSockets.WEBSOCKET);
- //Bind open/close (open will trigger attachEvents)
- bindSocketEvents();
- //On click... get info about the events being listened to...
- $("#pubsub").click(function () {
- //get guid listening to OnChatMessage in controller GenericText
- wsEventController.trigger("GetSubscriptions", { Alias: "GenericText", Event: "OnChatMessage" });
- //get ALL subscriptions
- wsEventController.trigger("GetAllSubscriptions", {});
- });
- $("#subscribe").click(function () {
- //Tell the eventcontroller that we have a new client listening to OnChatMessage on GenericText.
- //This will be done in the bind callback in the next version of the JSAPI.
- wsEventController.trigger("Subscribe", { Event: "OnChatMessage", Alias: "GenericText" });
- //Tell the eventcontroller that we have a new client listening to OnChatMessage on GenericText.
- //This will be done in the bind callback in the next version of the JSAPI.
- wsEventController.trigger("Subscribe", { Event: "OnFakeMessage", Alias: "GenericText" });
- });
- $("#unsubscribe").click(function () {
- ws.unbind("OnChatMessage", function () {
- wsEventController.trigger("Unsubscribe", { Alias: "GenericText", Event: "OnChatMessage" });
- });
- ws.unbind("OnFakeMessage", function () {
- wsEventController.trigger("Unsubscribe", { Alias: "GenericText", Event: "OnFakeMessage" });
- });
- });
- });
- // Deal with our WebSockets Events
- function attachEvents() {
- //fake subscription for OnchatMessage on controller GenericText
- ws.bind("OnChatMessage", function (d) {
- console.log(d);
- });
- //fake subscription for OnFakeMessage on controller GenericText
- ws.bind("OnFakeMessage", function (d) {
- console.log(d);
- });
- //Just bind getSubscriptions and console log
- wsEventController.bind("OnGetSubscriptions", function (d) {
- console.log(d);
- });
- //Just bind getAllSubscriptions and console log
- wsEventController.bind("OnGetAllSubscriptions", function (d) {
- console.log(d);
- });
- }
- function bindSocketEvents() {
- ws.bind("close", function (msg) {
- $('#infoDiv').text("No xSocketConnection :(");
- });
- ws.bind("open", function () {
- console.log('open');
- attachEvents();
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement