當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Socket.connect方法代碼示例

本文整理匯總了TypeScript中phoenix.Socket.connect方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Socket.connect方法的具體用法?TypeScript Socket.connect怎麽用?TypeScript Socket.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phoenix.Socket的用法示例。


在下文中一共展示了Socket.connect方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test_presence

function test_presence() {
  const socket = new Socket('/ws', {params: {userToken: '123'}});

  const channel = socket.channel('room:123', {token: '123'});
  const presence = new Presence(channel);

  let presenceState = {};

  const logState = (state: Object) => {
    Presence.list(state, (id: string) => id).forEach(console.log);
  };

  channel.on('presence_state', (state) => {
    presenceState = Presence.syncState(presenceState, state);
    logState(presenceState);
  });

  channel.on('presence_diff', (diff) => {
    presenceState = Presence.syncState(presenceState, diff);
    logState(presenceState);
  });

  socket.connect();

  channel.join();
}
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:26,代碼來源:phoenix-tests.ts

示例2: Socket

 return Observable.create((observer: Observer<string>) => {
   const options = { params: { token }};
   this.socket = new Socket('/socket', options);
   this.socket.onOpen(() => {
     observer.next(null);
   });
   this.socket.onError((err: Error) => {
     this.socket.disconnect();
     return observer.error(err);
   });
   this.socket.connect();
 })
開發者ID:akeating,項目名稱:peap,代碼行數:12,代碼來源:socket.service.ts

示例3: test_hooks

function test_hooks() {
  const socket = new Socket("/ws", {params: {userToken: "123"}});
  socket.connect();

  socket.onError(() => console.log("there was an error with the connection!"));
  socket.onClose(() => console.log("the connection dropped"));

  const channel = socket.channel("room:123", {token: '123'});

  channel.onError(() => console.log("there was an error!"));
  channel.onClose(() => console.log("the channel has gone away gracefully"))
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:12,代碼來源:phoenix-tests.ts

示例4: test_hooks

function test_hooks() {
  const socket = new Socket('/ws', {params: {userToken: '123'}});
  socket.connect();

  socket.onError(() => console.log('there was an error with the connection!'));
  socket.onClose(() => console.log('the connection dropped'));

  const channel = socket.channel('room:123', {token: '123'});

  channel.onError(() => console.log('there was an error!'));
  channel.onClose(() => console.log('the channel has gone away gracefully'));
}
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:12,代碼來源:phoenix-tests.ts

示例5: test_channel

function test_channel() {
  const socket = new Socket("/ws", {params: {userToken: "123"}});
  socket.connect();

  const channel = socket.channel("room:123", {token: '123'});

  channel.on("new_msg", msg => console.log("Got message", msg));

  channel.push("new_msg", {body: 'some value'}, 10000)
   .receive("ok", (msg) => console.log("created message", msg))
   .receive("error", (reasons) => console.log("create failed", reasons))
   .receive("timeout", () => console.log("Networking issue..."));

  channel.join()
    .receive("ok", ({messages}) => console.log("catching up", messages))
    .receive("error", ({reason}) => console.log("failed join", reason))
    .receive("timeout", () => console.log("Networking issue. Still waiting..."));
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:18,代碼來源:phoenix-tests.ts

示例6: connect

 connect() {
   this.socket.connect();
 }
開發者ID:mciastek,項目名稱:emotions-wheel-app,代碼行數:3,代碼來源:socket.service.ts

示例7:

//         assign(conn, :user_token, token)
//       else
//         conn
//       end
//     end
//
// Now you need to pass this token to JavaScript. You can do so
// inside a script tag in "web/templates/layout/app.html.eex":
//
//     <script>window.userToken = "<%= assigns[:user_token] %>";</script>
//
// You will need to verify the user token in the "connect/2" function
// in "web/channels/user_socket.ex":
//
//     def connect(%{"token" => token}, socket) do
//       # max_age: 1209600 is equivalent to two weeks in seconds
//       case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
//         {:ok, user_id} ->
//           {:ok, assign(socket, :user, user_id)}
//         {:error, reason} ->
//           :error
//       end
//     end
//
// Finally, pass the token on connect as below. Or remove it
// from connect if you don't care about authentication.

socket.connect()

export default socket
開發者ID:Dkendal,項目名稱:battle_snake_server,代碼行數:30,代碼來源:socket.ts

示例8: test_socket

function test_socket() {
  const socket = new Socket("/ws", {params: {userToken: "123"}});
  socket.connect();
}
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:4,代碼來源:phoenix-tests.ts


注:本文中的phoenix.Socket.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。